﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace DTO
{
    public class VOCABULARY
    {
        #region Attributes
        private string _strWord;
        private string _strType;
        private int _iIDTopic;
        private string _strTopicDisplay;
        private string _strPhoneticize;
        private string _strMeanEng;
        private string _strMeanVi;
        private DateTime _dtDateAdd;
        private short _sIsTwoWordVerb;
        private TOPIC _topic;
        #endregion

        #region Constuctor
        public VOCABULARY()
        {
            _strWord = "";
            _strType = "";
            _iIDTopic = -1;
            _strPhoneticize = "";
            _strMeanEng = "";
            _strMeanVi = "";
            _dtDateAdd = DateTime.Now;
            _sIsTwoWordVerb = 0;
            _topic = new TOPIC();
        }
        #endregion

        #region Properties
        public string Word
        {
            get { return _strWord; }
            set { _strWord = value; }
        }

        public string Type
        {
            get { return _strType; }
            set { _strType = value; }
        }

        public int idTopic
        {
            get { return _iIDTopic; }
            set { _iIDTopic = value; }
        }

        public string TopicDisplay
        {
            get { return _strTopicDisplay; }
            set { _strTopicDisplay = value; }
        }
        
        public string Phoneticize
        {
            get { return _strPhoneticize; }
            set { _strPhoneticize = value; }
        }

        public string MeanEng
        {
            get { return _strMeanEng; }
            set { _strMeanEng = value; }
        }

        public string MeanVi
        {
            get { return _strMeanVi; }
            set { _strMeanVi = value; }
        }

        public DateTime Date
        {
            get { return _dtDateAdd; }
            set { _dtDateAdd = value; }
        }

        public short isTwoWordVerb
        {
            get { return _sIsTwoWordVerb; }
            set { _sIsTwoWordVerb = value; }
        }
        #endregion

        #region Methods
        public void LoadVocabulary(XmlNode node)
        {
            XmlNode nodeTemp;
            nodeTemp = node.SelectSingleNode("Word");
            this._strWord = nodeTemp.InnerText;

            nodeTemp = node.SelectSingleNode("Type");
            this._strType = nodeTemp.InnerText;

            nodeTemp = node.SelectSingleNode("idTopic");
            this._iIDTopic = Int32.Parse(nodeTemp.InnerText);

            nodeTemp = node.SelectSingleNode("TopicDisplay");
            this.TopicDisplay = nodeTemp.InnerText;

            nodeTemp = node.SelectSingleNode("Phoneticize");
            this._strPhoneticize = nodeTemp.InnerText;

            nodeTemp = node.SelectSingleNode("MeanEng");
            this._strMeanEng = nodeTemp.InnerText;

            nodeTemp = node.SelectSingleNode("MeanVi");
            this._strMeanVi = nodeTemp.InnerText;

            nodeTemp = node.SelectSingleNode("Date");
            this._dtDateAdd = DateTime.Parse(nodeTemp.InnerText);

            nodeTemp = node.SelectSingleNode("isTwoWordVerb");
            this._sIsTwoWordVerb = short.Parse(nodeTemp.InnerText);
        }

        public void WirteXml(XmlTextWriter xw)
        {
            xw.WriteStartElement("Vocabulary");

            xw.WriteStartElement("Word");
            xw.WriteString(Word);
            xw.WriteEndElement();

            xw.WriteStartElement("Type");
            xw.WriteString(Type);
            xw.WriteEndElement();

            xw.WriteStartElement("idTopic");
            xw.WriteString(idTopic.ToString());
            xw.WriteEndElement();

            xw.WriteStartElement("Phoneticize");
            xw.WriteString(Phoneticize);
            xw.WriteEndElement();

            xw.WriteStartElement("MeanEng");
            xw.WriteString(MeanEng);
            xw.WriteEndElement();

            xw.WriteStartElement("MeanVi");
            xw.WriteString(MeanVi);
            xw.WriteEndElement();

            xw.WriteStartElement("Date");
            xw.WriteString(Date.ToString());
            xw.WriteEndElement();

            xw.WriteStartElement("isTwoWordVerb");
            xw.WriteString(isTwoWordVerb.ToString());
            xw.WriteEndElement();

            xw.WriteEndElement();
        }
        #endregion
    }
}
